package cn.santi.controller;

import cn.santi.domain.Staff;
import cn.santi.domain.StaffDate;
import cn.santi.domain.StaffTime;
import cn.santi.emuns.R;
import cn.santi.service.StaffDateService;
import cn.santi.service.StaffTimeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/time")
public class TimeController {
    @Autowired
    private StaffTimeService st;
    @Autowired
    private StaffDateService sd;
    //查询时间段showtiem
    @GetMapping("/showtiem")
    public R showtiem(int id){
        QueryWrapper<StaffTime> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("did",id);
        List<StaffTime> list = st.list(wrapper1);
        return R.ok(list);
    }
    @GetMapping("/gettiem")
    public R gettiem(int id,String setdate,String getdate ){
        QueryWrapper<StaffDate> wrapper = new QueryWrapper<>();
        wrapper.eq("sid", id)
                .ge("date", setdate) // date >= setdate
                .le("date", getdate); // date <= getdate
        return R.ok(sd.list(wrapper));
    }
    //查询日期
    @GetMapping("/showdate")
    public R showdate(int id){
        QueryWrapper<StaffDate> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        return R.ok(sd.getOne(wrapper).getDate());
    }
    //查询日期
    @GetMapping("/showtiems")
    public R showtiems(int id){
        QueryWrapper<StaffTime> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        return R.ok(st.getOne(wrapper).getTime());
    }

    //查询状态
    @GetMapping("/mode")
    public R mode(int stimeid){
        QueryWrapper<StaffTime> wrapper = new QueryWrapper<>();
        wrapper.eq("id",stimeid);
        return R.ok(st.getOne(wrapper));
    }
}
